package com._dev.social.mapper;

import com._dev.social.mode.domain.Comments;
import com._dev.social.mode.domain.response.CommentWithUserDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【comments】的数据库操作Mapper
 * @createDate 2024-11-09 14:05:37
 * @Entity com._dev.social.mode.domain.Comments
 */
@Mapper
public interface CommentsMapper extends BaseMapper<Comments> {
    @Select("SELECT c.comment_id AS cid, c.content, c.tid, c.uid, u.nickname, u.imageUrl, c.created_at AS created " +
            "FROM comments c " +
            "JOIN users u ON c.uid = u.uid " +
            "WHERE c.tid = #{tid}")
    List<CommentWithUserDTO> getCommentsWithUserByPostId(Long postId);

    @Select("""
                     SELECT 
                c.content, 
                c.tid, 
                c.uid, 
                u.nickname, 
                u.imageUrl, 
                c.created_at AS created
            FROM 
                comments c
            JOIN 
                users u ON c.uid = u.uid
            JOIN 
                threads t ON c.tid = t.tid 
            WHERE 
                t.userId = #{uid}
                AND c.uid != #{uid} 
            ORDER BY 
                c.tid, 
                c.created_at DESC;
                            """)
    List<CommentWithUserDTO> getAllThreadCommentByUserId(String uid);
}





